home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10598 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.5 KB  |  57 lines

  1. Path: newsfeed.internetmci.com!panix!usenet
  2. From: gugu@panix.com (Dae Choi)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: COOL: Something you can do in "C" you can NOT do in "C++"
  5. Date: 8 Mar 1996 19:58:27 GMT
  6. Organization: PANIX Public Access Internet and Unix, NYC
  7. Message-ID: <1094.6641T918T238@panix.com>
  8. References: <4hpov3$krb@qualcomm.com>
  9. NNTP-Posting-Host: gugu.dialup.access.net
  10. X-Newsreader: THOR 2.22 (Amiga;TCP/IP) *UNREGISTERED*
  11.  
  12.  
  13. >Hi,
  14.  
  15. >I am teaching myself C++, but my interest in the language just dropped.
  16. >I want to read cin as a binary file and output cout the same as well.  I read
  17. >the FAQs on C++ and guess what YOU CAN'T DO IT.
  18.  
  19. >Come on, THERE HAS TO BE A WORK AROUND!  OS/2 using EMX if it matters, but
  20. >hopefully something fairly portable.
  21.  
  22. Try this,
  23.  
  24. #include <fstream.h>
  25.  
  26. int main(void)
  27. {
  28.         int count;
  29.  
  30.         float price;
  31.  
  32.         // Opens output file stream "STOCK.DAT" as binary file
  33.         ofstream stocks("STOCKS.DAT",ios::binary);
  34.  
  35.         if (stocks.fail()) //checking if file didn't fail
  36.                 cerr <<"Error opening file Stock.dat"<<endl;
  37.         else {
  38.                 for (count =1;count<=30;count++)
  39.                 {
  40.                         price=count*100.0;
  41.                 //output to the file
  42.                         stocks.write((char *)&price,sizeof(float));
  43.                 }
  44.         stocks.close();
  45.         //closes the file
  46.         } //end if
  47. }  //end program
  48.  
  49. --------------------------------------------------------------------
  50.  
  51. I hope this helps...
  52.  
  53.  
  54.  
  55. gugu@panix.com
  56.  
  57.